package net.borderwars.util;

import java.util.Set;
import java.util.TreeMap;

/**
 * @author Eric
 *         * Date: Apr 7, 2003
 *         Time: 7:08:16 PM
 */
public class DoubleMapOfSets<Key1, Key2, Value> {

    private TreeMap<Key1, TreeMapOfSets<Key2, Value>> data = new TreeMap<Key1, TreeMapOfSets<Key2, Value>> ();

    public DoubleMapOfSets () {
    }

    public Set<Value> get (Object ia, Object ib) {
        TreeMapOfSets data2 = null;
        if (data.containsKey (ia)) {
            data2 = (TreeMapOfSets) data.get (ia);
            if (data2.getKeySet ().contains (ib)) {
                return (data2.getSet (ib));
            }
        }
        return (null);
    }

    public void put (Key1 ia, Key2 ib, Object value) {
        TreeMapOfSets<Key2, Value> data2;
        if (!data.containsKey (ia)) {
            data2 = new TreeMapOfSets<Key2, Value> ();
            data.put (ia, data2);
        }
        else {
            data2 = data.get (ia);
        }
        data2.put (ib, value);
    }
}
